package com.wellgoon.test.exam;

import java.math.BigDecimal;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正浮点数四舍五入
 */
public class HJ7 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个正浮点数：");
        while (sc.hasNext()) {
            String str = sc.nextLine();
            if (!str.matches("^[+]?[0-9]*?\\.?[0-9]+$")) {
                System.err.println("请输入一个正浮点数：");
                continue;
            }
            BigDecimal bd = new BigDecimal(str);
            System.out.println(str  + "四舍五入取整后是：" + bd.setScale(0,BigDecimal.ROUND_HALF_UP));
        }
    }
}
